<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .w {
            width: 600px;
            margin: 20px auto;
        }
        .slider_bar {
            position: absolute;
            top: 200px;
            right: 400px;
            width: 50px;
            height: 100px;
            background-color: green;
        }
        .header {
            height: 500px;
            background-color: orange;
        }
        .banner {
            height: 300px;
            background-color: skyblue;
        }
        .main {
            height: 600px;
            background-color: yellowgreen;
        }
        span {
            position: absolute;
            bottom: 0;
        }
    </style>
</head>
<body>
    <div class="slider_bar">
        <span class="goBack">返回顶部</span>
    </div>
    <div class="header w">头部区域</div>
    <div class="banner w">banner区域</div>
    <div class="main w">主体部分</div>

    <script>

        let sliderBar = document.querySelector('.slider_bar');
        let banner = document.querySelector('.banner');
        let bannerTop = banner.offsetTop;
        let sliderBarTop = sliderBar.offsetTop - bannerTop;

        document.addEventListener('scroll',function () {
            console.log(11);
            if (window.pageYOffset >= bannerTop) {
                sliderBar.style.position = 'fixed';
                sliderBar.style.top = sliderBarTop + 'px';
            } else {
                sliderBar.style.position = 'absolute';
                sliderBar.style.top = 200 + 'px';
            }
        });
    </script>
</body>
</html>